/*
 *MIT License
 *Copyright (c) 2021 fullset
 *@ClassName SysRoleDaoImpl
 *@date 2021/7/10 10:07
 *@author: pangps
 *@Description TODO
 */
package com.fs.orm.dao.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import com.fs.orm.dao.SysRoleDao;
import com.fs.orm.entity.SysRole;
import com.fs.orm.entity.SysUser;
import com.fs.orm.mapper.SysRoleMapper;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class SysRoleDaoImpl extends ServiceImpl<SysRoleMapper, SysRole> implements SysRoleDao {

    @Override
    public boolean addRole(SysRole sysRole) {
        sysRole.setCreateTime(new Date());
        sysRole.setUpdateTime(new Date());
        return SqlHelper.retBool(baseMapper.insert(sysRole));
    }

    @Override
    public boolean logicalDeleteById(String id) {
        SysRole sysRole = new SysRole();
        sysRole.setIsDeleted(1);
        UpdateWrapper<SysRole> roleUpdateWrapper = new UpdateWrapper<>();
        roleUpdateWrapper.eq("id", id);
        int update = baseMapper.update(sysRole, roleUpdateWrapper);
        return update > 0 ? true : false;
    }

    @Override
    public boolean batchDel(String ids) {
        String [] arr = ids.split(",");
        UpdateWrapper<SysRole> roleUpdateWrapper = new UpdateWrapper<>();
        roleUpdateWrapper.in("id", arr);
        roleUpdateWrapper.set("is_deleted", 1);
        int update = baseMapper.update(null, roleUpdateWrapper);
        return update > 0 ? true : false;
    }

    @Override
    public SysRole editRole(SysRole sysRole) {
        UpdateWrapper<SysRole> roleUpdateWrapper = new UpdateWrapper<>();
        roleUpdateWrapper.eq("id", sysRole.getId());
        baseMapper.update(sysRole, roleUpdateWrapper);
        return sysRole;
    }

    @Override
    public SysRole selectOne(QueryWrapper qWrapper) {
        return baseMapper.selectOne(qWrapper);
    }

    @Override
    public List<SysRole> getList(QueryWrapper qWrapper) {
        return baseMapper.selectList(qWrapper);
    }
}
